/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
import pojo.SanPham;
import service.SanPhamService;

/**
 *
 * @author MongKieu
 */
public class ChiTietSanPhamController extends AbstractController {

    private SanPhamService sanPhamService;

    public SanPhamService getSanPhamService() {
        return sanPhamService;
    }

    public void setSanPhamService(SanPhamService sanPhamService) {
        this.sanPhamService = sanPhamService;
    }

    public ChiTietSanPhamController() {
    }

    protected ModelAndView handleRequestInternal(
            HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        ModelAndView mv = new ModelAndView("ChiTietSanPham");
        try {
            String result = "false";
            SanPham sanPham;
            if (request.getParameter("ISBN") != null) {
                String ISBN = request.getParameter("ISBN");
                boolean kq = sanPhamService.kiemtraSanPhamTonTaiByISBN(ISBN);
                if (kq == true) {
                    result = "true";
                    mv.addObject("sanPham", sanPhamService.laySanPhamByISBN(ISBN));
                }
            }
            mv.addObject("thongBao", result);
        } catch (Exception ex) {
            System.out.println("Xay ra loi");
            mv = new ModelAndView("ThongBaoLoi");
            mv.addObject("messageError", "Xin chào bạn, thông tin tìm kiếm không hợp lệ.");
        }
        return mv;
    }
}
